/*
* 海康威视摄像头ROS采集程序
* 
* File   name consoleMain.cpp
* Discription 
* Version     1.0
* Author     yuancheng
* Create Date 2021_03_02
* Modification History
*/

#include <stdio.h>
#include <iostream>
//#include "GetStream.h"
#include "public.h"
#include <string.h>
#include "HiK_opencv.h"
using namespace std;

int main(int argc, char **argv)
{

  ros::init(argc, argv, "hk_opencv_multi");
  ros::NodeHandle nh;
  image_transport::ImageTransport it(nh);
  // 添加发布话题,根据需要修改数量
  image_transport::Publisher image_pub1 = it.advertise("hk_opencv_multi/image_raw1", 1);
  image_transport::Publisher image_pub2 = it.advertise("hk_opencv_multi/image_raw2", 1);
  ros::Rate loop_rate(20); //目前摄像头为20FPS,根据具体情况修改

  // Add file reader, 添加摄像头读取注册

  HK_camera camera1(&image_pub1, 0); //给定摄像头的编号和发布指针
  if (camera1.Init())
  {
    cout << "init success" << endl;
    if (camera1.Login("192.168.2.30", "admin", "nuaanrc505", 8000)) //注册摄像头,根据实际情况调整需求
    {
      cout << "login success" << endl;
      camera1.show(); //开始数据回调与解码操作
    }
    else
    {
      cout << "login fail" << endl;
    }
  }
  else
  {
    cout << "init fail" << endl;
  }

  HK_camera camera2(&image_pub2, 1);
  if (camera2.Init())
  {
    cout << "init success" << endl;
    if (camera2.Login("192.168.2.33", "admin", "nuaanrc505", 8000))
    {
      cout << "login success" << endl;
      camera2.show();
    }
    else
    {
      cout << "login fail" << endl;
    }
  }
  else
  {
    cout << "init fail" << endl;
  }

  while (ros::ok())
  {
    camera1.publish();
    camera2.publish();
    loop_rate.sleep();
  }
  return 0;
}
